<template>
  <div>
    <el-card>
      <el-input style="width:200px" @clear="searchExam" clearable v-model="searchForm.examTitle" placeholder="请输入考卷标题" class="input-with-select">
      </el-input>
      <el-input style="width:200px" @clear="searchExam" clearable v-model="searchForm.nickName" placeholder="请输入老师名称" class="input-with-select">
      </el-input>

      <el-button icon="Search" @click="searchExam" />
      <el-button @click="resetExam">重置</el-button>

      <el-table :data="tableData" border style="width: 100%;margin-top:20px">
        <el-table-column prop="examTitle" label="考试标题" width="400" />
        <el-table-column prop="courseName" label="所属课程名称" width="200" />
        <el-table-column prop="nickName" label="老师名称" width="200" />
        <el-table-column prop="createdAt" label="考试发布时间" width="200" />
        <el-table-column label="操作" width="330">
          <template #default="scope">
            <el-button type="primary" size="small" @click="examDetail(scope.row)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination style="margin-top:20px" :current-page="searchForm.current" :page-size="searchForm.size"
                     :page-sizes="[10, 20, 30, 40]" layout="->,total, sizes, prev, pager, next, jumper" :total="total"
                     @size-change="handleSizeChange" @current-change="handleCurrentChange" />
    </el-card>
  </div>
</template>




<script setup>
import {onBeforeMount, onBeforeUnmount, onMounted, reactive, ref} from "vue";
import examAPI from "../../api/exam.js";
import { useRouter } from 'vue-router'
const router = useRouter();

//图像
const imageKey = ref(0);

// Dom 挂载之后
onMounted(() => {
  getExamList();
})
// 课程数据
let tableData = ref([]);
let total = ref(0);

// 搜索条件
const searchForm = reactive({
  nickName:'',
  examTitle:'',
  pageNum: 1,
  pageSize: 10,
})

const getExamList = async () => {
  const res = await examAPI.page(searchForm);
  tableData.value = res.data.data.records;
  total.value = res.data.data.total;
}

//监听页的大小变化
const handleSizeChange = (size) => {
  searchForm.size = size;
  getExamList();
}
//翻页
const handleCurrentChange = (current) => {
  searchForm.current = current;
  getExamList();
}

//查询
const searchExam = () => {
  searchForm.current = 1;
  getExamList();
}
//重置
const resetExam = () => {
  searchForm.examTitle = '';
  searchForm.nickName = '';
  searchForm.current = 1;
  getExamList();
}

//获取课程详细数据
const examDetail =  (row) => {
  router.push({
    path:'/examination/examDetail',
    query:{
      "examId": row.examId
    }
  });
}
</script>


<style scoped>

</style>